<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/page/public/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>合同管理</title>
<% request.setAttribute("menu", 1); %>
<%@ include file="/WEB-INF/page/public/contentmeta.jsp"%>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="<%=basePath%>css/global.css" media="all" />
<link rel="stylesheet" href="<%=basePath%>plugins/font-awesome/css/font-awesome.min.css"/>
<link rel="stylesheet" href="<%=basePath%>css/system.css" media="all"/>
<link rel="stylesheet" href="<%=basePath%>css/tab.css" media="all" />
<style type="text/css">

/* 收款弹窗 */
.collection-money { display:none; }
.uploadcontractfile { display:none; }
.applyforbill { display:none; }

.layui-form-label i { color:red; padding-right: 3px; }

.addbg{width:380px;background:#2591d0;color:#fff;cursor:default;}   
.first{border:1px solid #c9c9c9;width:300px;border-radius:2px;}   
#append{width:380px;height:auto;background:#ffffff;border:1px solid #c9c9c9;display:none;border-radius:2px;margin-top:10px;position:absolute;z-index:99999;}
.item{width:380px;height:30px;line-height:30px;}  


/* 收款弹窗上传凭证样式开始 */
.uppzhide1,.uppzhide2 {display:none;}

/* 收款弹窗上传凭证样式结束 */

     .layui-tab-titles>li{color:#333;}
      .layui-tab-items{margin:30px 35px 10px 35px;}
      .layui-tab.layui-tab-card{margin-top:-20px;}
      .moretab{width:100%;height:200px;float:left;}
      .layui-input-blocks,.TM-he-tong .layui-input-blocks{margin-left:0px;float:left;}
      .layui-form-item p{float:left;font-size:14px;color:#333;margin: -3px 0 0 15px;}
      .layui-form-item p:nth-child(3){margin-left:5px;}
      .layui-form-items{width:100%;}
      .TM-he-tong .layui-form-items{width:33.333333%;margin-top:10px;margin-top:20px;float:left;}
      .layui-form-item p.ojpg{width:18px;height:19px;background:url(/images/tup.png);background-position:-15px -17px;}
      .layui-form-item p.ojpeg{width:18px;height:19px;background:url(/images/tup.png);background-position:-15px -17px;}
      .layui-form-item p.odocx{width:18px;height:19px;background:url(/images/tup.png);background-position:-15px -48px;}
      .layui-form-item p.opng{width:18px;height:19px;background:url(/images/tup.png);background-position:-15px -73px;}
      .layui-form-item p.ogif{width:18px;height:19px;background:url(/images/tup.png);background-position:-15px -104px;}
      .layui-form-item p.opdf{width:18px;height:19px;background:url(/images/tup.png);background-position:-15px -134px;}
      .layui-form-item p.odoc{width:18px;height:19px;background:url(/images/tup.png);background-position:-15px -48px;}
      .layui-form-item p.oxls{width:18px;height:19px;background:url(/images/tup.png);background-position:-15px -156px;}
      .layui-form-item p.oxlsx{width:18px;height:19px;background:url(/images/tup.png);background-position:-15px -156px;}
      .layui-btns{margin:20% 0 0 40%}
      .icheckbox_flat-blue{background:url(blues.png) no-repeat;}

</style>
</head>
<body>

<div class="admin-tab admin-user">
    <div class="tab-condition">
        <form class="layui-form clefix" id="htform" action="/customer/contractlisturl" method="post">
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="text" name="keyWord" id="keyWord"  autocomplete="off" placeholder="请输入关键字" class="layui-input" value="${pager.params.KeyWord }">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block" style="width:170px;">
                    <input type="text" style="width:170px;" name="sttime" id="sttime"  placeholder="开始时间" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this})" value="${pager.params.sttime}">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block" style="width:170px;">
                    <input type="text" style="width:170px;" name="entime" id="entime"  placeholder="结束时间" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this})" value="${pager.params.entime}">
                </div>
            </div>
            <div class="layui-form-item">
	            <input name="skipToPage" id="skipToPage"  type="hidden" value="${pager.pageNo}">
				<input type="hidden" id="pageNo" name="pageNo" value="${pager.pageNo}">
				<input type="hidden" id="totalPage" name="totalPage" value="${pager.totalPages}">
                <button class="layui-btn TM-btn-search searchbtn" lay-submit="" lay-filter="demo2"><i class="layui-icon layui-unselect layui-tab-close">&#xe615;</i>搜索</button>
               <button class="layui-btn refreshbtn"  type="button"><i class="layui-icon layui-unselect layui-tab-close ">&#x1002;</i>刷新</button>  
            </div>
        </form>
    </div>
    <div class="layui-field-box">
        <table class="site-table table-hover TM-table-news">
            <thead>
            <tr>
                <th style="width:5%;">编号</th>
                <th style="width:16%;">合作方</th>
                <th style="width:10%;">合同金额</th>
                <th style="width:10%;">服务费用</th>
                <th style="width:7%;">合同类型</th>
                <th style="width:10%;">收/付款金额</th>
                <th style="width:7%;">合同状态</th>
                <th style="width:10%;">签订时间</th>
                <th style="width:25%;">操作</th>
            </tr>
            </thead>
            <tbody>
	            
	             <c:forEach var="obj" items="${pager.resultList}" varStatus="o1">
	            	<tr>
		                <td>${o1.index+1}</td>
		                <td>${obj.customerInfo.cname}</td>
		                <td><fmt:formatNumber value="${obj.totalamount}" pattern="#,#00"/>元</td>
		                <td><c:if test="${obj.type==0}">无</c:if><c:if test="${obj.type==1}"><fmt:formatNumber value="${obj.servicecharge}" pattern="#,#00"/>元</c:if></td>
		                <td><dic:cf type="1" name="contract_type" value="${obj.contracttype}"/></td>
		                <td>
		                	<!-- 这里要显示的是 -->
		                	<c:if test="${obj.totalmoney>0}">
		                		<button  type="button" class='layui-btn layui-btn-mini ${obj.type==0?"":"layui-btn-danger"} showrecord' datatype="${obj.type}" data="${obj.id}"   datapid="${obj.pid}">${obj.type==0?"-":"+"}<fmt:formatNumber value="${obj.totalmoney}" pattern="#,#00"/>元</button>
		                	</c:if>
		                	<c:if test="${obj.totalmoney==null||obj.totalmoney<1}">
		                		无记录
		                	</c:if>
		                </td>
		                <td><dic:cf type="1" name="contract_state" value="${obj.state}"/></td>
		                <td>${obj.signingtime.substring(0,10)}</td>	
		                <td>
		                	<a class="layui-btn layui-btn-normal layui-btn-mini  showcontractinfo" data="${obj.type==0? obj.pid:obj.id}"   type="button">查看</a>
		                	<!-- 企业的一定显示修改 -->
		                	<c:if test="${obj.customerInfo.type == 1}">
		                	<%-- 	<a class="layui-btn layui-btn-normal layui-btn-mini  upcontractinfo" iddata="${obj.id}" typedata="${obj.type}" piddata="${obj.pid}"   type="button">修改</a> --%>
		                	</c:if>
		                	<!-- 人才的有付款记录的显示修改 -->
		                	<c:if test="${obj.customerInfo.type == 0 && obj.totalmoney>0}">
		                	<%-- 	<a class="layui-btn layui-btn-normal layui-btn-mini  upcontractinfo" iddata="${obj.id}" typedata="${obj.type}" piddata="${obj.pid}"   type="button">修改</a> --%>
		                	</c:if> 
		                	<c:if test="${obj.delsign == 0}">
		                		<a class="layui-btn layui-btn-normal layui-btn-mini  cancelcontract" iddata="${obj.id}" typedata="${obj.type}" piddata="${obj.pid}" type="button">撤回</a>
		                	</c:if>
		                    <c:if test="${obj.state <= 4}">
		                    	<!-- 收款 -->
		                    	<c:if test="${obj.type==0 && obj.countsign > 0}">
			                	  <a data-method="offset" data-type="auto" class="layui-btn layui-btn-normal layui-btn-mini dksqbtn"  data="${obj.id}"  datacategory="${obj.isadditional}" data2="${obj.customerInfo.id}" dtamount="${obj.totalamount}" dmoney="${obj.totalamount-obj.totalmoney}"  dcusid="${obj.cusid}"  dname="${obj.createuserName}">付款</a>
			                	</c:if>
			                	<!-- 付款 只有在合同有收款记录的时候，才会有付款按钮 -->
			                	<c:if test="${obj.type==1}">
			                	   <a data1="${obj.id}" data2="${obj.customerInfo.id}" data-method="offset" data-type="auto" dtamount="${obj.totalamount}" dmoney="${obj.totalamount-obj.totalmoney}" class="layui-btn layui-btn-normal layui-btn-mini collectionbtn">收款</a>
			                	</c:if>
		                    </c:if> 
		                    <c:if test="${obj.state != 8}">
		                       <a data-method="offset" data-type="auto" class="layui-btn layui-btn-normal layui-btn-mini upcontract" data="${obj.id}"  dcusid="${obj.cusid}">上传合同</a>
		                    </c:if> 
		                    <c:if test="${obj.state>2}"> 
		                    	<a data-method="offset" data-type="auto" class="layui-btn layui-btn-normal layui-btn-mini applybill" data="${obj.id}" dcusid="${obj.cusid}" dtamount="${obj.totalamount}">申请发票</a>
		                    </c:if>
		                </td>
		            </tr>
	             </c:forEach>
            </tbody>
        </table>
        <div class="admin-table-page">
            <div id="page" class="page"></div>
        </div>	
    </div>
</div>

<!-- 收款 -->
<div class="collection-money">
	<div class="TM-he-tong admin-entering">
		<form class="layui-form TM-entering-form" action="/customer/saveskmoneylog" id="collectionform" method="post" novalidate="novalidate" enctype="multipart/form-data">
			<div class="form-left" style="width: 40%;">
				<div class="layui-form-item">
	                <label class="layui-form-label"><i>*</i>现收款金额 : </label>
	                <div class="layui-input-inline" style="width:100px">
	                	<input type="text" class="layui-input" id="totalamount" name="totalamount">
	                </div>
	                <div class="layui-form-mid layui-word-aux" style="color:red">注意总收款金额</div>
            	</div>
            	<div class="layui-form-item">
	                <label class="layui-form-label">收款方式 : </label>
	                <div class="layui-input-block" >
	                	<select name="moneytype" lay-filter="moneytype">
	                		<option value="0">预付款</option>
	                		<option value="2">中期款</option>
	                		<option value="3">公示款</option>
	                		<option value="1">全款</option>
	                	</select>
	                </div>
            	</div>
            	<div class="layui-form-item">
	                <label class="layui-form-label"><i>*</i>打款户名 : </label>
	                <div class="layui-input-block" >
	                	<input type="text" id="compaccount" name="name" class="layui-input">
	                </div>
            	</div>
			</div>
			<div class="form-right" style="margin-left: 40px;">
				<div class="layui-form-item">
	                <label class="layui-form-label"><i>*</i>到帐时间 : </label>
	                <div class="layui-input-block" >
	                	<input type="text" id="arrivaltime" name="arrivaltime" class="layui-input" readonly="readonly" placeholder="yyyy-mm-dd" autocomplete="off" onclick="layui.laydate({elem: this})">
	                </div>
            	</div>
            	<div class="layui-form-item">
	                <label class="layui-form-label">类型 : </label>
	                <div class="layui-input-block" >
	                	<select name="transfertype" lay-filter="transfertype"> 
	                		<option value="1">转账</option>
	                		<option value="0">现金</option>
	                	</select>
	                </div>
            	</div>
            	<div class="layui-form-item">
	                <label class="layui-form-label"><i>*</i>收款账户 : </label>
	                <div class="layui-input-block" >
	                	<select name="bankname" id="myaccount"  lay-filter="myaccount"> 
	                	    <option value="">收款账户</option>
	                		 <dic:cf type="2" name="bank_name" value="" />
	                	</select>
	                </div>
            	</div>
			</div>
			
			<div class="layui-form-item TM-hetong-jilu">
	      		<label class="layui-form-label">打款备注 : </label>
	            <div class="layui-input-block">
	      			<textarea placeholder="请输入内容" name="remark" id="remark" autocomplete="off" class="layui-textarea"></textarea>
	    		</div>
     		</div>
     		
			<!-- 凭证上传开始 -->     		
     		<div>
     			<div class="layui-form-item TM-hetong-jilu">
	     			<label class="layui-form-label"><i>*</i>上传凭证1 : </label>
	     			<div class="layui-input-block" >
		            	<input type="file" class="layui-input" name="file" id="pzfile1" style="width: 40%"> 
		            	<span class="addpz" adddata="1" showdata="2">添加凭证</span>
		            </div>
     			</div>
     		
	     		<div class="layui-form-item TM-hetong-jilu uppzhide1">
	     			<label class="layui-form-label">上传凭证2 : </label>
	     			<div class="layui-input-block" >
		            	<input type="file" class="layui-input" name="file" id="pzfile2" style="width: 30%">
		            	<span class="addpz" adddata="2" showdata="3">添加凭证</span>
		            </div>
	     		</div>
     		
	     		<div class="layui-form-item TM-hetong-jilu uppzhide2">
	     			<label class="layui-form-label">上传凭证3 : </label>
	     			<div class="layui-input-block" >
		            	<input type="file" class="layui-input" name="file" id="pzfile3" style="width: 30%">
		            </div>
	     		</div>
     		</div>
     		<!-- 凭证上传结束 -->
     		
     		<input name="skipToPage" id="skipToPage"  type="hidden" value="${pager.pageNo}">
			<input type="hidden" id="pageNo" name="pageNo" value="${pager.pageNo}">
			<input type="hidden" id="totalPage" name="totalPage" value="${pager.totalPages}">
     		<input type="hidden" name="contractid" class="contractid" value="">
     		<input type="hidden" name="cusid" class="cusid" value="">
     		<input type="hidden" name="type"   value="1">
		</form>
	</div>
</div>

<!-- 垫款详情弹框 -->
<div id="TM-layui-diankuan" style="display:none;">
	<div class="TM-he-tong admin-entering">
		<form class="layui-form TM-entering-form" action="" id="diankuanform"   novalidate="novalidate">
        <div class="form-left">
            <div class="layui-form-item">
                <label class="layui-form-label">申请人 : </label>
                <div class="layui-input-block dkrname" ></div>
                 <input type="hidden" name="cusid" id="rcid" >
                  <input type="hidden" name="type" value="0" >
                  <input type="hidden" name="contractid" id="contractid" value="">
            </div>
            <div class="layui-form-item telitem" style="display:none;">
               <label class="layui-form-label"><i>*</i><span>收款人电话 :</span> </label>
               <div class="layui-input-inline" style="width:200px">
        			<input type="text" name="tel" id="tel"    autocomplete="off" class="layui-input"  >
        			<input type="hidden" name="isadditional" id="isadditional" value="0"   >
        		</div>
        		 <div class="layui-form-mid layui-word-aux">便于财务核查</div>
            </div>  
            <div class="layui-form-item">
                <label class="layui-form-label"><i>*</i><span>金额 : </span></label>
                <div class="layui-input-inline" style="width:100px">
        			<input type="text" name="totalamount" id="hktotalamount" readonly="readonly"  total="0" autocomplete="off" class="layui-input" >
        			<input type="hidden" id="hidehktotalamount" >
        		</div>
        		<div class="layui-form-mid layui-word-aux">合同总金额(<span id="dkhtzje"></span>)</div>
            </div>   
            <div class="layui-form-item">
                <label class="layui-form-label"><i>*</i><span>户名 : </span></label>
                <div class="layui-input-block">
        			<input type="text" name="name" id="name"   autocomplete="off" class="layui-input" >
        		</div>
            </div> 
            <div class="layui-form-item">
                <label class="layui-form-label"><i>*</i><span>卡号 : </span></label>
                <div class="layui-input-block">
        			<input type="text" name="cardnumber" id="cardnumber" onkeyup="formateBankNo(this)" onkeydown="formateBankNo(this)"  autocomplete="off" class="layui-input" >
        		</div>
            </div>                  
        </div>
        <div class="form-right">
            <div class="layui-form-item">
                <label class="layui-form-label"><i>*</i><span>付款类型 : </span></label>
                <div class="layui-input-block">
        		  <select name="paytype" lay-filter="paytype">
			        <!-- <option value="0" selected="selected">垫款</option> -->
			        <option value="1" selected="selected">全款</option>
			      </select>
        		</div>
            </div>
            <div class="layui-form-item warehouse" style="display:;">
               <label class="layui-form-label"><i>*</i><span>证书用途: </span></label>
               <div class="layui-input-block utype">
			      <select name="usetype"  id="usetype" lay-filter="usetype">
			        <option value="">证书用途</option>
			        <option value="0">挂资质</option>
			        <option value="1">挂项目</option>
			      </select>
			    </div>
            </div> 
            <div class="layui-form-item">
            	<label class="layui-form-label"><i>*</i><span>转账类型 : </span></label>
                <div class="layui-input-block">
			      <select name="transfertype" lay-filter="transfertype">
			      	<option value="1">转账</option>
			        <option value="0">现金</option>
			      </select>
			    </div>
            </div>    
             <div class="layui-form-item">
            	<label class="layui-form-label"><i>*</i><span>来源 : </span></label>
                <div class="layui-input-block">
			      <select name="source" lay-filter="source">
			           <option value="0">个人</option>
			        <option value="1">中介</option>      
			      </select>
			    </div>
            </div>    
            <div class="layui-form-item">
                <label class="layui-form-label"><i>*</i><span>开户行 : </span></label>
                <div class="layui-input-block">
        			<input type="text" name="bankname" id="kw" autocomplete="off" class="layui-input" placeholder="请输入银行名称">
        			<div id="append"></div>
        		</div>
            </div> 
                   
        </div>
     	<div class="layui-form-item TM-hetong-jilu">
      		<label class="layui-form-label"><i>*</i>费用说明 : </label>
            <div class="layui-input-block">
      			<textarea placeholder="请输入内容" name="remark"  id="dkremark" class="layui-textarea"></textarea>
    		</div>
     	</div> 
    </form>
	</div>
</div>

<!-- 上传合同 -->
<div class="uploadcontractfile">
	<div class="TM-he-tong admin-entering">
	        <div class="tab-condition">   	
			<div class="layui-tab layui-tab-card " lay-filter="cupfiles">
			  <ul class="layui-tab-title  layui-tab-titles">
			    <li class="layui-this" lay-id="1">上传合同</li>
			    <li lay-id="2">选择合同</li>
			  </ul>
			  <div class="layui-tab-content" style="height:400px;">
			    <div class="layui-tab-item layui-tab-items layui-show"> 
			    	<div class="moretab"> 
		<form action="/customer/uploadcontractfile" method="post" enctype="multipart/form-data" id="upcontractform">
			<div class="layui-form-item">
				<label class="layui-form-label"><i>*</i><span>上传附件 : </span></label>
				<div class="layui-input-block" style="width: 40%;">
					<!-- <input type="file" name="file" class="layui-input"> -->
					<button class="layui-btn addcfile layui-btn-normal" type="button">
					  <i class="layui-icon">&#xe608;</i> 请选择合同文件
					</button>
				</div>
				<div class="layui-form-mid layui-word-aux">多个文件选择请按住Shift键</div>
			</div>
			<!-- <div class="layui-form-item TM-hetong-jilu">
  				<label class="layui-form-label">备注 : </label>
        		<div class="layui-input-block">
  					<textarea placeholder="请输入内容" name="remark" class="layui-textarea"></textarea>
				</div>
    		</div>  -->
    		<input type="hidden" class="contractids" name="contractid">
		</form>
           	</div>
					 <button class="layui-btn layui-btns layui-btn-primary layui-btn-small tabfileqx">取消</button>
			    </div>
			    <div class="layui-tab-item layui-tab-items">
			    
					   <div class="moretab fileshow">  
		                   
		                </div>
			    
			    	 <button class="layui-btn layui-btns layui-btn-small layui-btn-normal tabfileqr">确认</button>
               		 <button class="layui-btn layui-btns layui-btn-primary layui-btn-small tabfileqx">取消</button>
			     
			    </div>
			  </div>
			</div>
		</div> 
	</div>
</div>

<!-- 申请发票 -->
<div class="applyforbill">
	<div class="TM-he-tong admin-entering">
		<form action="/customer/applyforbill" method="post" id="applybill">
			<div class="form-left">
				<div class="layui-form-item">
                	<label class="layui-form-label">发票抬头 : </label>
                	<div class="layui-input-block">
                		<input type="text" name="title" class="layui-input">
                	</div>
            	</div>
            	<div class="layui-form-item">
                	<label class="layui-form-label">用途 : </label>
                	<div class="layui-input-block">
                		<input type="text" name="used" class="layui-input">
                	</div>
            	</div>
			</div>
			<div class="form-right">
				<div class="layui-form-item">
                	<label class="layui-form-label">开票金额 : </label>
                	<div class="layui-input-block">
                		<input type="text" name="totalamount"  class="layui-input totalamount">
                	</div>
            	</div>
			</div>
			<div class="layui-form-item">
	      		<label class="layui-form-label">备注 : </label>
	            <div class="layui-input-block">
	      			<textarea placeholder="请输入内容" name="remark" class="layui-textarea"></textarea>
	    		</div>
     		</div> 
     		<input type="hidden" class="contractids" name="contractid">
     		<input type="hidden" name="cusid" class="cusids">
		</form>
	</div>
</div>



 <link rel="stylesheet" href="<%=basePath%>js/uploader/webuploader.css"> 
 <script type="text/javascript" src="/js/uploader/webuploader.min.js"></script>


<script>
    layui.config({
        base: 'plugins/layui/modules/'
    });
    layui.use(['element','laypage','form','laydate','layer'], function() {
        var $ = layui.jquery,
                laypage = layui.laypage,
                layer = layui.layer,
                element = layui.element(); //Tab的切换功能，切换事件监听等，需要依赖element模块
        var form = layui.form();
                
        var pageNo = $("#pageNo").val();
    	var totalPage = $("#totalPage").val();
    	var tjstate =0;
        //page
        laypage({
            cont: 'page',
            curr: pageNo//'${pager.pageNo}'
            ,pages: totalPage//'${pager.totalPages}' //总页数
            ,
            groups: 5 //连续显示分页数
            ,
            jump: function(obj, first) {
                //得到了当前页，用于向服务端请求对应数据
                var curr = obj.curr;
                if(!first) {
                	$("#skipToPage").val(curr);
                	$("#htform").submit();
                }
            }
        });
        
	    //撤回合同
        $(".cancelcontract").on("click",function(){
        	
        	//获取id和type
        	var id = $(this).attr("iddata");
        	var type = $(this).attr("typedata");
        	var pid = $(this).attr("piddata");
        	layer.confirm('确认撤回合同吗？', {
        		  btn: ['确定','取消'] //按钮
        		}, function(){
        			$.ajax({
						 type : "post",
						 data : {id:id,type:type,pid:pid},
						 url : "/customer/cancelcontract",
						 dataType : "json",
						 success : function(data){
							layer.msg("删除成功",function(){
								window.location.reload();
							});					 
						 }
        			});
        		}, function(){
        		 // layer.msg('好的，取消撤回合同。');
        		});
        });
	    
	    
        
        
                
        //更新渲染
        form.render();
        //设置收款的合同id,cusid为空
        $(".contractid").val("");
        $(".cusid").val("");
        
        

        
 
		//点击查看合同详情
        $('.showcontractinfo').on('click',function(){
        	var id =  $(this).attr("data"),
        	url =  "/customer/contractinfo?id="+id;
            parent.layer.open({
                title:'合同详情',
                type:2,
                content:url,
                shadeClose:true,
                btnAlign:'c',
                area:['99%','99%']
            });
        });
		
		
        //点击弹出合同修改界面
        $(".upcontractinfo").on("click",function(){
        	var id = $(this).attr("iddata");
        	var type = $(this).attr("typedata");
        	var pid = $(this).attr("piddata");
        	var url =  "/customer/updatecon?id="+id+"&type="+type+"&pid="+pid;
        	parent.layer.open({
                title:'合同详情',
                type:2,
                content:url,
                shadeClose:true,
                btnAlign:'c',
                area:['99%','99%']
            });
        });
		
		
		
		
		
		
		
		
		
		//点击上传合同，弹出上传合同页面
		$(".upcontract").on("click",function(){
			 element.tabChange('cupfiles', 1);
			var id = $(this).attr("data");
                 	var cusid = $(this).attr("dcusid");
			$(".contractids").val(id);
			var title = "";
			layer.open({
				title : title,
				type : 1,
				content : $(".uploadcontractfile"),
				shadeClose:true,
        		//btn: ['确认', '取消'],
        		btnAlign:'c',
        		area:['90%','620px'],
        		/*yes: function(){
        			//$("#upcontractform").submit();
        		}*/
			});
			
			
			
	        var uploader = new WebUploader.Uploader({
			    swf: '/js/uploader/Uploader.swf',
			    auto:true,
			    pick:{id:".addcfile"},
			    
			    formData:{contractid:id},
			    accept: {
		            extensions: 'gif,jpg,jpeg,bmp,png',
		            mimeTypes: 'image/*'
		        },
			    server: '/customer/uploadcontractfile' 
			    // 其他配置项
			});
			
			uploader.on("uploadSuccess",function(file,reason ){
				if(reason.size==0){
				
					layer.msg("文件上传失败!",{icon: 2});
				}else{
					layer.msg("上传文件成功!",{icon: 1,time: 2000}, function(){
						window.location.reload();
					});
				} 
		    });
			uploader.on("error",function(type ){
				layer.msg("文件上传出现错误!",{icon: 2});
		    });
			
			var template ='<div class="layui-form-item layui-form-items" pane=""> <div class="layui-input-block layui-input-blocks">'
	                +'<input type="checkbox" name="cusfileids" value="{fileid}" lay-skin="primary" title="{filedes}"> </div> <p class="o{fileext}"></p> <p><a href="/file/{fileid}" title ="{filedes}" taget="_blank">{filename}.{fileext}</p> </div>';
			$.ajax({
				 type : "post",
				 url : "/customer/filesinfo"+cusid,
				 dataType : "json",
				 success : function(data){
					 		
					 var html ="";
					 if(data!=null){
						 for(var i=0;i<data.length;i++){
							var current =data[i];
							html+= template.replace(new RegExp("{fileid}","gm"),current.fileid).replace(new RegExp("{filedes}","gm"),current.remark).replace(new RegExp("{filename}","gm"),current.filesinfo.name).replace(new RegExp("{fileext}","gm"),current.filesinfo.suffix)
						 } 
						 $(".fileshow").html(html)
						 
					 }
					 
				 }
			 });
		});
	         $(".tabfileqr").on("click",function(){
			var ckfiles = "";
			$('input[name="cusfileids"]:checked').each(function(){ 
				ckfiles+= "file="+$(this).val()+"&"; 
			}); 
			if(ckfiles.length>0){
				layer.closeAll();
				var url = "/customer/uploadcontractfileajax?"+ckfiles+"contractid="+$(".contractids").val();
				$.ajax({
					 type : "post",
					 url : url,
					 dataType : "json",
					 success : function(data){ 
						 if(data!=null&&data==1){
							 layer.msg('保存文件成功！', {icon: 1},function(){
	      		 					window.location.reload();
	      		 				});
						 }else{
							 layer.msg("保存文件出现问题！",{icon: 0});
						 } 
					 }
				 });
			}else{
				 layer.msg("请选择文件！",{icon: 0});
			}
		})
		$(".tabfileqx").on("click",function(){
			layer.closeAll();
		})
		
		
		//点击申请发票
		$(".applybill").on("click",function(){
			var id = $(this).attr("data");
			var totalamount = $(this).attr("dtamount");
			var cusid = $(this).attr("dcusid");
			$(".contractids").val(id);
			$(".totalamount").val(totalamount);
			$(".cusids").val(cusid);
			var title = "申请发票";
			layer.open({
				title : title,
				type : 1,
				content : $(".applyforbill"),
				shadeClose:true,
        		btn: ['确认', '取消'],
        		btnAlign:'c',
        		area:['90%','90%'],
        		yes: function(){
        			$("#applybill").submit();
        		}
			});
		});
		
		
                
      //点击查看收付款记录
        $('.showrecord').on('click',function(){
        	var title='付款记录',id =  $(this).attr("data"),pid=$(this).attr("datapid"),type =$(this).attr("datatype")
        	    url =  "/customer/moneyrecord?contractid="+id+"&type="+type+"&pid="+pid;
        	if(type==1){
        		title='回款记录';
        	} 
            parent.layer.open({
                title:title,
                type:2,
                content:url,
                shadeClose:true,
                btnAlign:'c',
                area:['90%','90%']
            });
        });
        
		
      	//点击搜索
      	$(".searchbtn").on("click",function(){
    	  $("#skipToPage").val(1);
    	  form.submit();
		});
      
      
        //点击搜索
      	$("#htform").validate({
      		rules : {},
      		messages : {},
      		errorPlacement : function(error, element) {
      			layer.tips(error.text(), element, {
 					tips: [2,tipColor],
 	     		 tipsMore: true
 	     		});
      		},
      		submitHandler : function(form) {
      			form.submit();
      		}
      	});
        
        //点击收款，弹出收款弹窗
        $(".collectionbtn").on("click",function(){
        	var id = $(this).attr("data1");
        	var cusid = $(this).attr("data2");
        	var money = $(this).attr("dmoney");
        	var totalamount = $(this).attr("dtamount");
        	//$("#totalamount").val(money);
        	//$("#skhtzje").text(totalamount);
        	//这里加一个判断,判断已经在审核和已经通过的款项够不够合同金额,如果够的话就不能点击
        	$.ajax({
        		type:"post",
        		data:{cusid:cusid,id:id},
        		url:"/customer/checkisover",
        		dataType:"json",
        		success:function(data){
        			if (data == 0) {
        				layer.msg("所收款项已达或超过合同金额,无法继续收款")
        			} else {
        				layer.open({
        	        		title:"收款",
        	        		type:1,
        	        		content:$(".collection-money"),
        	        		shadeClose:true,
        	        		btn: ['确认', '取消'],
        	        		btnAlign:'c',
        	        		area:['99%','99%'],
        	        		yes: function(){
        	        			//确定收款
        	        			if(tjstate ==0){
       	        					$(".contractid").val(id);
               	        			$(".cusid").val(cusid);
               	        			if (validatorCollecttin(totalamount)&&validatorCollecttin(remark)){
               	        				tjstate =1;
               	        				var compaccount = $("#compaccount").val();
               	               	      	var myaccount = $("#myaccount").val();
               	               	      	//var remark = $("#remark").val(); 
               	                      	//$("#remark").val("打款账户："+compaccount+ "     收款账户："+myaccount+"    \r\n"+remark);
               	        			  	var values = $("#collectionform").serialize();
               	        			  	/*
               	        			  		2017/10/12更新
               	        			  		因为要上传文件,不能用ajax,改用表单提交
               	        			  	*/
               	        			  	$("#collectionform").submit();
               	        			  	
               	        			}
               	        				 
        	                  	 }else{
        	                  		 layer.msg("信息提交中,请勿重复提交",{icon: 0});
        	                  	 }
        	        			
        	        		
        	            	},
        	            	success: function(layero, index){
        	       			  tjstate =0;
        	       		    }
        	        	});
        			}
        		}
        	});
        });
        
        //收款点击添加凭证
        $(".addpz").on("click",function(){
        	var adddata = $(this).attr("adddata");
        	var showdata = $(this).attr("showdata");
        	$(".uppzhide"+adddata).show();
        	$(this).hide();
        });
        
        
        //收款的验证
        var validatorCollecttin = function(tamount){
			        	
        	var totalamount = $.trim($("#totalamount").val());
        	var arrivaltime = $("#arrivaltime").val();
        	var compaccount = $("#compaccount").val();
        	var myaccount = $("#myaccount").val();
        	var remark = $("#remark").val();
        	var pzfile1 = $("#pzfile1").val();
        	if (pzfile1 == null || pzfile1 == "") {
        		layer.tips("请上传收款凭证",$("#pzfile1"),{
        			tips: [2,tipColor],
        			tipsMore: true
        		});
        		return false;
        	}
        	if (totalamount == null || totalamount.length < 1) {
        		layer.tips("请输入总收款金额", $("#totalamount"), {
 					tips: [2,tipColor],
     	     		 tipsMore: true
     	     		});
        		return false;
        	}else{
        		
        		var reg = /^[0-9]*$/;
            	if (!reg.test(totalamount)) {
        			layer.tips("总收款金额请填写数字", $("#totalamount"), {
     					tips: [2,tipColor],
         	     		tipsMore: true
         	     	});
        			return false;
           		}
            	
        		//这里是验证收款的总金额
        	   /* var money = totalamount -tamount;
        	   if(money>0){
        		   layer.tips("输入金额已超过合同金额"+money, $("#totalamount"), {
    					tips: [2,tipColor],
        	     		 tipsMore: true
        	     	});
        		   return false;
        	   } */
        	}
        	if (arrivaltime == null || arrivaltime.length < 1) {
        		layer.tips("请输入到帐时间", $("#arrivaltime"), {
 					tips: [2,tipColor],
     	     		 tipsMore: true
     	     		});
        		return false;
        	}
        	if (compaccount == null || compaccount.length < 1) {
        		layer.tips("请输入到打款账户", $("#compaccount"), {
 					tips: [2,tipColor],
     	     		 tipsMore: true
     	     		});
        		return false;
        	}
        	if (myaccount == null || myaccount.length < 1) {
        		
        		
        		layer.tips("请选择收款账户",$("#myaccount").parent().find("input"), {
 					tips: [2,tipColor],
     	     		 tipsMore: true
     	     		});
        		return false;
        	}
        	/* if (remark == null || remark.length < 1) {
        		layer.tips("请输入打款备注", $("#remark"), {
 					tips: [2,tipColor],
     	     		 tipsMore: true
     	     		});
        		return false;
        	} */
        	
        	return true;
        }
        
        
 
    	jQuery.validator.addMethod("checkmoney", function(value,element) {
        	var flag = true;
        	value = $.trim(value);
        	total = $(element).attr("total");
        	
        	var money = total-value;
      	    if(money<0){
      		 flag= false;
      	    }
            return flag;
        }, "输入金额不能大于合同金额");
    	
    	jQuery.validator.addMethod("tel", function(value,element) {
        	var flag = true;
        	value = $.trim(value);
        	var ia =  $("#isadditional").val();
        	if(ia==1){
        		 if(value<1){
              		 flag= false;
              	 }
        	} 
            return flag;
        }, "请输入收款人电话，便于财务核查！");
    	
    	//检测所付款项是否超出
    	jQuery.validator.addMethod("checkover", function(value,element) {
    		var flag = true;
    		var money = $("#hidehktotalamount").val();
    		if(value.length<1 || (parseInt(value)>parseInt(money))){
    			flag= false;
    		}
    		return flag;
    	},"超出应付款总金额");
  
    	
    	
      //垫款表单
      $("#diankuanform").validate({
      	rules: {
      	 
      		arrivaltime : {
      			required:false
      		},
      		tel:{
      			tel:true
      		},
      		totalamount : {
      			required:true,
      			digits:true,
      			checkover:true
      		},
      		name : {
      			required:true
      		},
      		cardnumber : {
      			required:true
      		},
      		bankname : {
    			required:true
    		},
    		remark : {
    			required:true
    		}
      		
      	},
      	messages: {
      		 
      		arrivaltime : {
      			required:"请选择回款时间"
      		},
      		tel:{
      			required:"请填写收款人电话，便于财务核查！" 
      		},
      		totalamount : {
      			required:"请填写付款金额",
      			digits:"请填写正确金额",
      			checkover:"超出最大付款金额"
      		},
      		name : {
      			required:"请填写姓名"
      		},
      		cardnumber : {
      			required:"请填写银行卡号"
      		},
      		bankname : {
    			required:"请填写开户行"
    		},
    		remark : {
    			required:"请填写费用说明"
    		}
      	},
      	errorPlacement: function(error, element) {
      		 tjstate =0;
      		layer.tips(error.text(), element, {
      			tips: [2,tipColor],
       		 tipsMore: true
       		});
      		}, 
         	 submitHandler: function(formobj) {  
         		
         	  	var ia =  $("#isadditional").val();
         	   
         		if(ia==0){
         			var tel = $("#usetype").val();
         			if (tel == null || tel.length < 1) {
         				//$("#myaccount").parent().find("input")
                		layer.tips("请选择证书用途", $("#usetype").parent().find("input"), {
         					tips: [2,tipColor],
             	     		 tipsMore: true
             	     		});
                		return false;
                	}
         		}else{
         			var tel = $("#tel").val();
         			var remark = $("#dkremark").val();
         			 $("#dkremark").val("收款人电话："+tel+"    "+remark);
         		} 
         		  
         		 
         	   tjstate =1;
      			var values = $("#diankuanform").serialize();
      			$.ajax({
      				type : "post",
      				url : "/customer/savecollectionmoneylog",
      				data : values,
      				dataType : "json",
      				async : false,
      				success : function(data){
      					if (data == 1) {
      						layer.closeAll();
      		 				layer.msg('付款申请成功等待审核', {icon: 1},function(){
      		 					window.location.reload();
      		 				});
      					} else {
      						tjstate= 0;
      						layer.msg("付款信息申请失败");
      					}
      				}
      			}); 
      	      return  false;
            }
      	
      });


      	//付款申请按钮
      	$(".dksqbtn").on("click",function(){
      	   
      		var ct = $(this).attr("datacategory");//是否为附加合同
      		//重置表单
      		document.getElementById("diankuanform").reset();
      		var id = $(this).attr("data");
      		var cusid = $(this).attr("dcusid");
      		var rcname = $(this).attr("dname");
      		var money = $(this).attr("dmoney");
         	var totalamount = $(this).attr("dtamount");
      		
      		/*
  				2017/10/11添加
  				点击付款按钮,先判断是否有付款记录,
  				如果有付款记录,提示已有付款记录,是否继续添加付款
  			*/
  			
  			$.ajax({
  				type:"post",
        		data:{cusid:cusid,contractid:id,sign:1},
        		url:"/customer/getmlcbytype",
        		dataType:"json",
        		async:false,
        		success:function(data){
					if (data > 0) {
						//说明有付款记录,显示提示
						layer.confirm("该合同已有"+ data +"条付款记录,是否继续添加付款?",{
							btn:['继续','取消']
						},function(){
							layer.closeAll();
							payfunction(rcname,cusid,id,money,totalamount,totalamount,ct);
						},function(){
							layer.closeAll();
							return false;
						});				
					} else {
						//直接打开
						payfunction(rcname,cusid,id,money,totalamount,totalamount,ct);
					}
        		}
  			});
      	});
    });
    
    //付款的function
    function payfunction(rcname,cusid,id,money,totalamount,totalamount,ct){
    	
    	$(".dkrname").text(rcname);
  	    $("#rcid").val(cusid);
  	    $("#contractid").val(id); 
     	$("#hktotalamount").val(money);
     	$("#hidehktotalamount").val(totalamount);
     	$("#hktotalamount").attr("total",totalamount);
     	$("#dkhtzje").text(totalamount);
     	$("#isadditional").val(ct);
     	$.ajax({
     		type:"post",
    		data:{cusid:cusid,id:id},
    		url:"/customer/checkisover",
    		dataType:"json",
    		success:function(data){
    			if (data == 0) {
    				layer.msg("所付款项已达或超过合同金额,无法继续付款")
    			} else {
    				 $(".telitem").hide();
  		      		 $(".warehouse").show();   
    				//显示附加合同页面
    			    if(ct==1){
    		      		 $(".telitem").show();
    		      		 $(".warehouse").hide();  
    		      	}
    				layer.open({
    	                title:'申请付款',
    	                type:1, 
    	                content:$('#TM-layui-diankuan'),
    	                btn: ['提交付款', '取消'],
    	                shadeClose:true,
    	                btnAlign:'c',
    	                area:['99%','99%'],
    	                yes: function(){ 
    	                	 if(tjstate ==0){
    	                	    $("#diankuanform").submit();
    	                		//tjstate =1;
    	                	  
    	                	 }else{
    	                		 layer.msg("信息提交中,请勿重复提交",{icon: 0});
    	                	 }
    	                },
    	      		   success: function(layero, index){
    	      			  tjstate =0;
    	      		  }
    	            });
    			}
    		}
     	});
    }
    
</script>
<script type="text/javascript">

	$("#kw").on("keyup",function(){
		var key = $(this).val();
		var html = "";
		if (key != null && key != "") {
			$.ajax({
				type : "post",
				data : {key : key},
				url : "/customer/selectbankname",
				dataType : "json",
				 scriptCharset: 'utf-8',
				success : function(data){
					if (data.length > 0) {
				        $.each(data,function(i, item) {
				        	 html = html + "<div class='item' onmouseenter='getFocus(this)' onClick='getCon(this);'>" + item.bankname + "</div>"
				        });
					} else {
						html = "";
					}
					if(html != ""){
    	      	        $("#append").show().html(html);
    	      	    }else{
    	      	        $("#append").hide().html("");
    	      	    }
				}
			});
		} else {
			return;
		}
		
	});

	function getFocus(obj){
	    $(".item").removeClass("addbg");
	    $(obj).addClass("addbg");
	}
	function getCon(obj){
	    var value = $(obj).text();
	    $("#kw").val(value);
	    $("#append").hide().html("");
	}

</script>


</body>
</html>